<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="600px" append-to-body>
        <el-form ref="form" :model="model" :rules="rules" inline label-width="110px" label-suffix=":">
            <el-form-item label="广告系列ID" prop="id">
                <el-input v-model.trim="model.id" placeholder="请输入广告系列ID" clearable style="width: 100%"></el-input>
            </el-form-item>
            <!-- <el-form-item label="广告系列名" prop="title">
                <el-input v-model.trim="model.title" placeholder="请输入广告系列名" clearable style="width: 100%"></el-input>
            </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" :loading="save" :disabled="save" @click="submit">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { addExpert } from '@/api/advertisement'
export default {
    name: 'ExpertDetailDialog',
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
        type: {
            type: String,
            default: '',
        },
        category: {
            type: String,
            default: '1',
        }
    },
    data() {
        return {
            model: {
                id: '',
                title: '',
            },
            rules: {},
            dict: { },
            save: false,
            list: []
        }
    },
    computed: {
        title() {
            return `新增广告系列`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    watch: {
        params: {
            handler(val) {
                if (val.id) {
                    this.getDetail()
                }
            },
            immediate: true,
            deep: true,
        },
    },
    mounted() {},
    methods: {
        getDetail() {
            this.loading = true
            const params = { id: this.params.id }
        },
        submit() {
            this.$refs.form.validate(valid => {
                if (!valid) {
                    return
                }
                const params = { ...this.model }
                if (this.save) {
                    return
                }
                this.save = true
                addExpert(params)
                    .then(res => {
                        this.$message.success(res.msg)
                        this.dialogVisible = false
                        this.$emit('success')
                    })
                    .finally(() => {
                        this.save = false
                    })
            })
        },
        cancel() {
            this.dialogVisible = false
        },
    },
}
</script>

<style>

</style>
